#include"process.h"
#include<string.h>
#include<unistd.h>

#define NUM 101
#define STYLE '='

void process_v1()
{
    char buffer[NUM];
    memset(buffer,0,sizeof(buffer)); // buffer数组里全设置成0
    const char* table = "|/-\\";
    int len = strlen(table);

    int cnt = 0;
    while(cnt <= 100)
    {
        printf("[%-100s][%d%%][%c]\r",buffer,cnt,table[cnt%len]);
        fflush(stdout);
        buffer[cnt] = STYLE;
        cnt++;
        sleep(6);
    }
    printf("\n");
}

void FlushProcess(double total, double current)
{
    char buffer[NUM];
    memset(buffer,0,sizeof(buffer));
    const char* table = "|/-\\";
    int len = strlen(table);

    static int cnt = 0;
    int num =(int)(current*100/total);
    for(int i = 0;i < num;i++)
    {
        buffer[i] = STYLE;
    }
    
    double rate = current/total;
    cnt %= len;
    printf("[%-100s][%.1f%%][%c]\r",buffer,rate*100,table[cnt]);
    cnt++;
    fflush(stdout);
}

